//
//  RTJBidRecordsDetailsCell.m
//  RuiTaiJinProject
//
//  Created by jayson on 2018/12/18.
//  Copyright © 2018年 leewei. All rights reserved.
//

#import "RTJBidRecordsDetailsCell.h"

@implementation RTJBidRecordsDetailsCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    [self backview:_bg_view viewOfcornerRadius:5];
    [self backview:_bg_view2 viewOfcornerRadius:5];
    [self backview:_bg_view3 viewOfcornerRadius:5];
    [self backview:_bg_view4 viewOfcornerRadius:5];

}


-(void)backview:(UIView *)backview viewOfcornerRadius:(NSInteger)cornerRadius{
    
    backview.layer.cornerRadius = cornerRadius;
    backview.layer.shadowColor = [UIColor colorForHex:@"#dbc9cc"].CGColor;
    backview.layer.shadowOffset = CGSizeMake(-1, 1);
    backview.layer.shadowOpacity = 0.5;
    backview.layer.shadowRadius = 5;
    
}

-(void)setData:(NSDictionary *)data{
    
    if (_isAuto) {
        
        self.retaLab.text = [NSString stringWithFormat:@"%@%@",data[@"data"][@"rate"],@"%"];
        self.timeLimitLab.text = [NSString stringWithFormat:@"%@个月",data[@"data"][@"repay_time"]];
        self.lab.text = @"出借期限";
        self.lab5.text = @"出借日期";

        if (_isCancel == YES ) {
            
            _bg_img.image = [UIImage imageNamed:@"bg_zdtbycx"];
            
        }else{
           
            NSInteger status = [data[@"data"][@"status"]integerValue];
            
            if (status == -1) {
                
                _bg_img.image = [UIImage imageNamed:@"bg_zdtbycx"];
                
            }
            
        }
        
        self.timeLab.text = [NSString stringWithFormat:@"%@",data[@"data"][@"create_time_format"]];;
        
        self.lab1.text = @"出借金额";
        self.dateLab.text = @"已匹配金额";
        self.lab2.text = @"预期收益";
        self.lab3.text = @"未匹配金额";

        self.typeLab.text = [NSString stringWithFormat:@"%@元",data[@"data"][@"money_format"]];
        self.typeLab.textColor = [UIColor colorForHex:@"#666666"];
        self.moneyLab.text = [NSString stringWithFormat:@"%@元",data[@"data"][@"used_money_format"]];
        self.interestLab.text = [NSString stringWithFormat:@"%@元",data[@"data"][@"earnings_money_format"]];
        self.shouyiLab.text = [NSString stringWithFormat:@"%@元",data[@"data"][@"balance_money_format"]];

        NSString *pullreta =[NSString stringWithFormat:@"%@",data[@"data"][@"increase_rate"]];
        
        if ([pullreta isEqualToString:@"<null>"]||pullreta.length == 0) {
            
            self.retaLab1.hidden = YES;
            
        }else{
            
            self.retaLab1.text = [NSString stringWithFormat:@"+%@%@",pullreta,@"%"];
            
        }
        
        _lab6.text = [NSString stringWithFormat:@"%@个",data[@"data"][@"match_deal"]];
        
        _lab4.text = @"投标详情";
        _bg_view2.hidden = YES;
        _bg_view2H.constant = 0;
        _top1.constant = 0;
        _top2.constant = 0;
        
        _bg_view3.hidden = NO;
        _hetong.hidden = NO;
        _view.hidden = YES;
        _viewH.constant = 0;
        
    }else{
        
        self.retaLab.text = [NSString stringWithFormat:@"%@%@",data[@"data"][@"rate"],@"%"];
//      self.dateLab.text = [NSString stringWithFormat:@"%@",data[@"data"][@"create_time"]];
        self.dateLab.text = @"出借金额";
        NSInteger repay_time_type = [data[@"data"][@"repay_time_type"]integerValue];
        
        if (repay_time_type == 0) {
            
            self.timeLimitLab.text = [NSString stringWithFormat:@"%@天",data[@"data"][@"repay_time"]];
            
        }else if (repay_time_type == 1){
            
            self.timeLimitLab.text = [NSString stringWithFormat:@"%@个月",data[@"data"][@"repay_time"]];
        }else{
            
            self.timeLimitLab.text = [NSString stringWithFormat:@"%@年",data[@"data"][@"repay_time"]];
        }
        
        self.lab.text = @"项目期限";
        self.lab2.text = @"预期收益";
        self.lab3.text = @"回款日期";
//        NSString *endtime = [NSString stringWithFormat:@"%@",data[@"data"][@"repay_end_time"]];
//
//        if (endtime.length!=0) {
//
//           endtime = [endtime substringWithRange:NSMakeRange(0, 10)];
//            self.lab5.text = @"回款日期";
//            self.timeLab.text = endtime;
//        }else{
        
            self.lab5.text = @"目前状态";
            self.timeLab.text = [NSString stringWithFormat:@"%@",data[@"data"][@"deal_status_format"]];
//        }

        
        
        self.moneyLab.text = [NSString stringWithFormat:@"%@元",data[@"data"][@"money"]];
        self.typeLab.text = [NSString stringWithFormat:@"%@",data[@"data"][@"loantype_format"]];
        self.interestLab.text = [NSString stringWithFormat:@"%@元",data[@"data"][@"profit_format"]];
//        self.shouyiLab.text = [NSString stringWithFormat:@"%@元",data[@"data"][@"month_interest_format"]];
        self.shouyiLab.text = @"查看详情    ";
        NSString *pullreta =[NSString stringWithFormat:@"%@",data[@"data"][@"plus_rate"]];
        
        if ([pullreta isEqualToString:@"<null>"]) {
            
            self.retaLab1.hidden = YES;
            
        }else{
            
            self.retaLab1.text = [NSString stringWithFormat:@"+%@%@",pullreta,@"%"];
            
        }
        
//        NSString *ecv_name =[NSString stringWithFormat:@"%@",data[@"data"][@"ecv_name"]];
//
//        if ([ecv_name isEqualToString:@"<null>"]) {
//
//            self.hongbaoLab.text = @"无可用红包";
//
//        }else{
//
//            self.hongbaoLab.text = [NSString stringWithFormat:@"%@",ecv_name];
//
//        }
//
//        NSString *interestrate_name =[NSString stringWithFormat:@"%@",data[@"data"][@"interestrate_name"]];
//
//        if ([interestrate_name isEqualToString:@"<null>"]) {
//
//            self.jiaxiLab.text = @"无可用加息券";
//
//        }else{
//
//            self.jiaxiLab.text = [NSString stringWithFormat:@"%@",interestrate_name];
//
//        }
        
//        NSString *ecv_money =[NSString stringWithFormat:@"%@",data[@"data"][@"ecv_money"]];
//        NSString *totalMoney=[NSString stringWithFormat:@"%@",data[@"data"][@"money"]];
//        NSInteger money = [ecv_money integerValue];
//        NSInteger paymoney = [totalMoney integerValue];
//        
//        if ([ecv_money isEqualToString:@"<null>"]) {
//            
//            self.paymoneyLab.text = [NSString stringWithFormat:@"%ld.00 元",paymoney];
//            
//        }else{
//            
//            self.paymoneyLab.text = [NSString stringWithFormat:@"%ld.00 元",paymoney - money];
//            
//        }
        
        _lab6.hidden = YES;
        NSInteger is_completion_contract = [data[@"data"][@"is_completion_contract"]integerValue];
        _bg_view3.hidden = is_completion_contract== 0 ? YES : NO;
        _hetong.hidden = is_completion_contract== 0 ? YES : NO;
        _view.hidden = is_completion_contract== 0 ? YES : NO;
        
    }
}

-(void)setHuikuanData:(NSDictionary *)huikuanData{
    
    NSInteger status = [huikuanData[@"status"]integerValue];
    [self textColor:status];
    
    _huikuan.text = huikuanData[@"number"];
    _huikuanDate.text =[NSString stringWithFormat:@"%@",huikuanData[@"true_repay_time_format"]];
    _huikuanStatus.text =  huikuanData[@"status_format"];
    _yuqiHuikuan.text = [NSString stringWithFormat:@"预期还款日：%@",huikuanData[@"repay_day_format"]];
    _huikuanType.text = [NSString stringWithFormat:@"还款类型：%@",huikuanData[@"type"]];
    _huikuanBenjin.text =  [NSString stringWithFormat:@"本金：%@元",huikuanData[@"self_money_format"]];
    _huikuanLixi.text =  [NSString stringWithFormat:@"利息：%@元",huikuanData[@"interest_money_format"]];
    _huikuanMoney.text =  [NSString stringWithFormat:@"还款金额：%@元",huikuanData[@"repay_money_format"]];

}

-(void)textColor:(NSInteger)status{
    
    _huikuan.textColor = status == 1 ? [UIColor colorForHex:@"#999999"]:  [UIColor colorForHex:@"#FE623C"];
    _huikuanDate.textColor = status == 1 ? [UIColor colorForHex:@"#999999"]:  [UIColor colorForHex:@"#333333"];
    _huikuanStatus.textColor = status == 1 ? [UIColor colorForHex:@"#999999"]:  [UIColor colorForHex:@"#FE623C"];
    _yuqiHuikuan.textColor = status == 1 ? [UIColor colorForHex:@"#999999"]:  [UIColor colorForHex:@"#333333"];
    _huikuanType.textColor = status == 1 ? [UIColor colorForHex:@"#999999"]:  [UIColor colorForHex:@"#333333"];
    _huikuanBenjin.textColor = status == 1 ? [UIColor colorForHex:@"#999999"]:  [UIColor colorForHex:@"#333333"];
    _huikuanLixi.textColor = status == 1 ? [UIColor colorForHex:@"#999999"]:  [UIColor colorForHex:@"#333333"];
    _huikuanMoney.textColor = status == 1 ? [UIColor colorForHex:@"#999999"]:  [UIColor colorForHex:@"#333333"];

    
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
